package com.cyq.day04;

public class ClassWork03 {
    public static void main(String[] args) {
        Fibonacci1();
        Fibonacci2(20);
    }
    public static void Fibonacci1(){
        int sum=0;
        int a=0;
        int b=1;
        int c;
        for (int i=0;i<18;i++){
            c=a+b;
            a=b;
            b=c;
            sum+=c;
        }
        System.out.println(sum+1);
    }
    public static int Fibonacci2(int n){
        int sum=1;
        if (n==0){
            return 0;
        }else if (n==1||n==2){
            return 1;
        }else {
            int fibArray[]=new int[n+1];
            fibArray[0]=0;
            System.out.println("第1项斐波拉契数为0");
            fibArray[1]=1;
            System.out.println("第2项斐波拉契数为1");
            fibArray[2]=1;
            System.out.println("第3项斐波拉契数为1");
            for (int i=3;i<n;i++){
                fibArray[i]=fibArray[i-2]+fibArray[i-1];
                sum+=fibArray[i];
                System.out.println("第"+(i+1)+"项斐波拉契数为"+fibArray[i]);
            }
            System.out.println(n+"项斐波拉契数的和为"+(sum+1));
            return fibArray[n];
        }
    }
}
